package Entities;

import java.util.ArrayList;

import processing.core.PApplet;

import Shapes.Ball;
import Shapes.Flow;
import Shapes.Node;

public class Process {

	String type; // 1-farming 2-manufacturing 3-transportation 4-retail 5-cooking 6- waste 0-exertion/digesting
	
	int isByproduct; // byproduct like eggs
	
	ArrayList<Material> input = null; // 
	ArrayList<Material> output = null; // 
    ArrayList<Impact> impact = null; // 

	public Material outputmaterial = null; //
	public Material outputfood = null;    // 
	
    public float duration = 0;
    
    public int posx,poxy,scalse, index; // for graphics
    
    String info = "";
    
    public Process(){
    	
    }
    
    public void copyProcess(Process s) {
		// TODO Auto-generated method stub
    	this.type = s.type;
    	this.info = s.info;
    	this.duration = s.duration;
    	
    	ArrayList<Material> temin = new ArrayList<Material>();
    	for(int i = 0; i < s.getInput().size(); i++)
    	{
    		Material m = new Material();
    		m.copyMaterial(s.getInput().get(i));
    		temin.add(m);
    	}
        this.setInput(temin);
    	
    	ArrayList<Material> temout = new ArrayList<Material>();
    	for(int i = 0; i < s.getOuput().size(); i++)
    	{
    		Material m = new Material();
    		m.copyMaterial(s.getOuput().get(i));
    		temout.add(m);
    	}
    	this.setOutput(temout);
    	
    	ArrayList<Impact> temim = new ArrayList<Impact>();
    	for(int i = 0; i < s.getImpact().size(); i++)
    	{
    		Impact m = new Impact();
    		m.copyImpact(s.getImpact().get(i));
    		temim.add(m);
    	}
    	this.setImpact(temim);
		
	}
    public void setType(String t){
    	this.type = t;
    }
    
    public String getType(){
    	return this.type;
    }
    
    public void setDuration(float d){
    	this.duration = d;
    }
    
    public float getDuration(){
    	return this.duration;
    }
    
    public void setInfo(String in){
    	this.info = in;
    }
    
    public String getInfo(){
    	return this.info;
    }
    
	public void setOutput(Material m)
	{
		this.outputmaterial = m;
	}
	
	
	public void setInput(ArrayList<Material> in){
		this.input = in;
	}
	
	public ArrayList<Material> getInput(){
		return this.input;
	}
	
	public void setOutput(ArrayList<Material> out){
		this.output = out;
	}
	
	public ArrayList<Material> getOuput(){
		return this.output;
	}
	
	public void setImpact(ArrayList<Impact> im){
		this.impact = im;
	}
	
	public ArrayList<Impact> getImpact(){
		return this.impact;
	}
	
	public float getWaste()
	{
		return 0;
	}

	public float getEnergy() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	//-------------------------------------------------------------------------------------------------------------------------------------------------//
	//here we return the shape to the graphic interface for each process, there should be a node and a edge
	
	public Node getCheckBox(PApplet p){
		 Node checkbox = new Node(p);
		 ArrayList<String> instrings = new ArrayList<String>();
		 ArrayList<String> outstrings = new ArrayList<String>();
		 ArrayList<String> imstrings = new ArrayList<String>();
		 
		 if((input == null)||(output == null)||(impact == null)){
			 return null;
		 }
		 
		 for(int i = 0; i<input.size(); i++){
		//	 if(input.get(i).getIsAdd() == 1){
			 String para = input.get(i).name + ": " +input.get(i).getQuantity() + input.get(i).getUnit();
			 instrings.add(para);
		//	 }
		 }
		 
		 for(int i = 0; i<output.size(); i++){
			// if(output.get(i).getIsAdd() == 1){
			 String para = output.get(i).name + ": " +output.get(i).getQuantity() + output.get(i).getUnit();
			 outstrings.add(para);
			 //}
		 }
		 
		 for(int i = 0; i<impact.size(); i++){
			 String para = impact.get(i).getType() + ": " +  impact.get(i).name + ": " +impact.get(i).getQuantity() + impact.get(i).getUnit();
			 imstrings.add(para);
		 }
		 
		checkbox.setup(posx,poxy,scalse/4,instrings,outstrings,imstrings);
		return checkbox;
	}
	
	public Ball getCenterBall(PApplet p){
		
		Ball centerball = new Ball(p);
		centerball.setup(getType() ,posx,poxy,scalse/5, index,(int) this.duration*1000); //x,y,size of the ball
		return centerball;	
	}
	
	public Flow getFlowmass(PApplet p, int startx, int starty, int endx,int endy, float speed){
		Flow flowmass = new Flow(p);
	    flowmass.setup(30, startx,starty,endx,endy,speed);
	   // flowmass.setup(5, , des);
		return flowmass;
	}
	
	public  void setupGraph(int x, int y, int s, int in){
		this.posx =x;
		this.poxy = y;
		this.scalse = s;
		this.index = in;
	}

	
	
	
}
